package com.itheima.controller;



import com.itheima.common.ResultData;
import com.itheima.domain.PmsSkuStock;
import com.itheima.manager.PmsSkuStockManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * sku的库存 前端控制器
 * </p>
 *
 * @author XiaoRan
 * @since 2022-08-02
 */
@Slf4j
@RestController
@CrossOrigin(origins = "*")
public class PmsSkuStockController {
    @Autowired
    public PmsSkuStockManager pmsSkuStockManager;

    //批量更新sku库存信息
    @PostMapping("/sku/update/{pid}")
    public ResultData update(@PathVariable Integer pid , @RequestBody List<PmsSkuStock> pmsSkuStocks) {
        log.info("传递的id为{},传递的要修改的参数为{}",pid,pmsSkuStocks);
        pmsSkuStockManager.updateSku(pid, pmsSkuStocks);
        return ResultData.ok("", "");
    }

    //根据商品ID及sku编码模糊搜索sku库存
    @GetMapping("/sku/{pid}")
    public ResultData getSku(@PathVariable Integer pid,String keyword) {
        List<PmsSkuStock> pmsSkuStocks = pmsSkuStockManager.getSku(pid, keyword);
        return ResultData.ok(pmsSkuStocks, null);
    }

}
